<div class="layuimini-container layuimini-page-anim" divname="UserLog">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="search"> <i class="layui-icon"></i> 查询 </button>

                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="refresh"> 刷新 </button>
            </div>
        </script>

        <table class="layui-hide" id="UserLogPage" lay-filter="UserLogPageTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">详情</a>
        </script>
    </div>
</div>

<script>
    layui.use(['form', 'table', 'miniPage', 'element', 'faceAPI'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        var faceAPI = layui.faceAPI;
        form.render();

        IniSearchPar();

        table.render({
            elem: '#UserLogPage',
            //**************************异步请求开始***********************
            url: 'api/UserLog/GetLogs',
            method: 'post',
            where: faceAPI.UserLogSearchPageResult.field,
            headers: {
                //token: 'sasasas',
                Authorization: "Bearer " + faceAPI.GetJWTToken()
            },//增加Token验证头
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) { //res 即为原始返回的数据
                if (res.errCode == 0) {
                    var data = res.content;
                    var ret = {
                        "code": res.errCode, //解析接口状态
                        "msg": res.error, //解析提示文本
                        "count": data.totalCount, //解析数据长度
                        "data": data.dataList //解析数据列表
                    };
                    return ret;

                } else {
                    /*layer.open({
                        title: '请求错误',
                        content: '(' + res.errCode + ')' + res.error
                    });  */

                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": 0, //解析数据长度
                        "data": [] //解析数据列表
                    };
                }

            },
            //**************************异步请求结束***********************

            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { field: 'userName', width: 120, title: '操作员', sort: true },
                { field: 'logTime', width: 200, title: '时间', sort: true },
                { field: 'logType', width: 120, title: '类型', sort: true },
                { field: 'logDetail', title: '内容', sort: true },
                { title: '操作', width: 80, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });



        
        function IniSearchPar() {
            var par = {
                field: {
                    logTimeBegin: dayjs().subtract(7, 'day').format("YYYY-MM-DD") + ' 00:00:00' ,
                    logTimeEnd: dayjs().format("YYYY-MM-DD") + ' 23:59:59',
                },
                result:true
            };
            
            faceAPI.UserLogSearchPageResult = par;
        }
        /**
         * toolbar事件监听
         */
        table.on('toolbar(UserLogPageTableFilter)', function (obj) {
            if (obj.event === 'search') {  // 查询操作
                var content = miniPage.getHrefContent('page/UserLog/search.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '搜索日志',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                    end: function (layero, index) {

                        var rst = faceAPI.UserLogSearchPageResult;
                        if (rst != null && rst.result) {
                            console.log("刷新")
                            //执行搜索重载
                            table.reload('UserLogPage', {
                                page: {
                                    curr: 1
                                }
                                , where: rst.field
                            }, 'data');

                        };

                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
            else if (obj.event == 'refresh') {
                //执行搜索重载
                IniSearchPar();
                var rst = faceAPI.UserLogSearchPageResult;
                table.reload('UserLogPage', {
                    page: {
                        curr: 1
                    }, where: rst.field
                }, 'data');
            }
        });


        table.on('tool(UserLogPageTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {

                var content = miniPage.getHrefContent('page/UserLog/Detail.html');
                var openWH = miniPage.getOpenWidthHeight();
                faceAPI.UserLogDetail = data;//向layer页面传值，传值主要代码
                var index = layer.open({
                    title: '日志详情',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            
        });



    });



</script>